package com.jrx.anytxn.reporting.controller;

import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.reporting.dto.MrCustomerInfoRes;
import com.jrx.anytxn.reporting.dto.MrLoanAccountInfoRes;
import com.jrx.anytxn.reporting.service.ILoanAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xqy
 * @version 1.0
 * @date 2020/4/14
 */
@Api(tags = "监管报送的订单信息接口")
@RestController
@RequestMapping(value = "/mr/loan")
public class MrLoanController {

    @Autowired
    private InfoService infoService;
    @Autowired
    private ILoanAccountService loanAccountService;

    @ApiOperation(value = "监管报送的借款信息集合查询接口")
    @GetMapping(value = "/loanList")
    public TxnRespResult<TxnPage> getMrCustomersByCusIdOrMobileOrIdNumber(@RequestParam String channel, @RequestParam String customerId, @RequestParam String loanId,
                                                                         @RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String beginDate, @RequestParam String endDate) {
        TxnRespResult<TxnPage> result = new TxnRespResult();
        String tenantId=String.valueOf(infoService.getUser().getProjectId());
        TxnPage<MrLoanAccountInfoRes> mrCustomersByCusIdAndLoanId = loanAccountService.getLoansByCusIdAndLoanId(channel, customerId, loanId, tenantId, beginDate, endDate,pageNum,pageSize);
        return result.getSuccess(mrCustomersByCusIdAndLoanId);
    }
    @ApiOperation(value = "监管报送的借款信息查询接口")
    @GetMapping(value = "/info")
    public TxnRespResult<MrLoanAccountInfoRes> getMrCustomersByCusIdOrMobileOrIdNumber(@RequestParam String channel, @RequestParam String customerId, @RequestParam String loanId) {
        TxnRespResult<MrLoanAccountInfoRes> result = new TxnRespResult();
        String tenantId=String.valueOf(infoService.getUser().getProjectId());
        MrLoanAccountInfoRes loanByCusIdAndLoanId = loanAccountService.getLoanByCusIdAndLoanId(channel, customerId, loanId, tenantId);
        return result.getSuccess(loanByCusIdAndLoanId);
    }
}